package ss.pku.jsa.worklist.graph;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import ss.pku.jsa.worklist.om.Constraint;
import ss.pku.jsa.worklist.om.Expression;

public class ConstraintGraph<M, K> extends DirectedGraph<Constraint<M, K>> {

	public ConstraintGraph(Constraint<M, K>[] constraints) {
		super(constraints);

	}

	@Override
	public int isDirectConnected(Constraint<M, K> a, Constraint<M, K> b) {
		Expression<M, K> exp = b.getRight();
		if (exp.containsElement(a.getLeft())) {
			return 1;
		} else {
			return 0;
		}
	}

	public Map<M, Set<Constraint<M, K>>> getInfluenceGraph() {
		Map<M, Set<Constraint<M, K>>> result = new HashMap<M, Set<Constraint<M,K>>>();
		for(int i = 0; i < this.matrix.length; ++i){
			Set<Constraint<M, K>> set = new HashSet<Constraint<M,K>>();
			Constraint<M, K> constraint = this.vertical[i];
			for(int j = 0; j < this.matrix.length; ++j){
				if(matrix[i][j] != 0)
				{
					set.add(vertical[j]);
				}
			}
			result.put(constraint.getLeft().getNode(), set);
		}
		return result;
	}
	
}
